import numpy as np
import matplotlib.pyplot as plt
from matplotlib_venn import venn2

def jaccard_similarity(set1, set2):
    intersection = len(set1.intersection(set2))
    union = len(set1.union(set2))
    return intersection / union

def jaccard_distance(set1, set2):
    return 1 - jaccard_similarity(set1, set2)

# 创建两个集合
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['C', 'D', 'E', 'F'])

# 计算杰卡德距离
distance = jaccard_distance(set1, set2)

# 绘制韦恩图
plt.figure(figsize=(10, 6))
venn2([set1, set2], set_labels=('Set 1', 'Set 2'))
plt.title(f'Jaccard Distance Visualization\nDistance = {distance:.2f}')
plt.show()

print(f"Jaccard distance between set1 and set2: {distance:.2f}")